#include "spl.includes.h"
#include "splib.h"

using namespace SPLib;
using namespace SPLib::Ole;

BOOL Clipboard::SetText(LPCSTR text, int nTextLen)
{
    BOOL fResult = TRUE;
    OleInitialize(0);

    FORMATETC fmtEtc = { CF_TEXT, 0, DVASPECT_CONTENT,
        -1, TYMED_HGLOBAL };
    STGMEDIUM stgMed = { TYMED_HGLOBAL, { 0 }, 0 };
    IDataObject *pDataObject;
    stgMed.hGlobal = StringToHandle(text, nTextLen);

    if (CreateDataObject(&fmtEtc, &stgMed, 1, &pDataObject) == S_OK) {
        OleSetClipboard(pDataObject);
        OleFlushClipboard();

        pDataObject->Release();
    } else {
        fResult = FALSE;
    }

    ReleaseStgMedium(&stgMed);
    OleUninitialize();
    return fResult;
}